<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>guessNum</title>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>

</head>
<body>
    <button id="reset">重新开始一局游戏</button><br>
    请输入要猜的数字<input type="text" id="text"><button id="guess">猜</button><br>
    已经猜的次数：<span id="count">0</span><br>
    结果：<span id="result"></span>

    <script>
        $(document).ready(function(){
            let num=Math.floor(Math.random()*100)+1;
            let count=0;
            console.log(num);
            $("#guess").click(function(){
                count++;
                $("#count").text(count);
                let userNum=$("#text").val();
                if(userNum>num){
                    $("#result").text("猜大了!");
                }else if(userNum<num){
                    $("#result").text("猜小了!");
                }else{
                    $("#result").text("猜对了!");
                }
            });

            $("#reset").click(function(){
                num=Math.floor(Math.random()*100)+1;
                console.log(num);
                count=0;
                $("#count").text(count);
                $("#result").text("");
                $("#text").val("");
            });
            
        });
    </script>
</body>
</html>